﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;

namespace SchoolManagementSystem.Details
{
    //nhà cung cấp hàng hóa
    public partial class Product_ProviderUC : DetailUC
    {
        public Product_ProviderUC()
        {
            InitializeComponent();
            this.ObjectName = "nhà cung cấp";
            this.Code = "Product_Provider";
            this.Type = new Product_Provider();
        }


        protected override long DetailDisplay()
        {
            Product_Provider data = new Product_Provider();
            if (ID > 0)
            {
                data = (Product_Provider)RegisterService.RegisterServices.ProductProviderService.GetByID(ID);

            }

            txtname.Text = data.Name;
            txtcode.Text = data.Code;
            txtaddress.Text = data.Address;
            txtemail.Text = data.Email;
            txtphone.Text = data.Phone;
            txttaxcode.Text = data.TaxCode;
            ckactive.Checked = data.Active;


            return ID;

        }

        protected override long Save()
        {
            Product_Provider data = new Product_Provider();
            if (ID > 0)
            {
                data = (Product_Provider)RegisterService.RegisterServices.ProductProviderService.GetByID(ID);

            }

            data.Code = txtcode.Text;
            data.Name = txtname.Text;
            data.TaxCode = txttaxcode.Text;
            data.Phone = txtphone.Text;
            data.Email = txtemail.Text;
            data.Address = txtaddress.Text;
            data.Active = ckactive.Checked;

            ID = RegisterService.RegisterServices.ProductProviderService.Save(data);

            return ID;
        }


        public override bool Delete(long SelectedID)
        {

            return RegisterService.RegisterServices.ProductProviderService.Delete(RegisterService.RegisterServices.ProductProviderService.GetByID(SelectedID));

        }

        private void Product_ProviderUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(groupControl1.Controls);
        }
    }
}
